//test browser type
var user = navigator.userAgent;
var browser = {};
browser.opera = user.indexOf("Opera") > -1 && typeof window.opera == "object";
browser.ie = user.indexOf("MSIE") > -1 && !browser.opera;
browser.ff = user.indexOf("Firefox") > -1;
browser.chrome = user.indexOf("Chrome") > -1;
browser.safari = user.indexOf("Safari") > -1;
var ready = false;

function loginButtonMouseOver(o)
{
    if (browser.ie)
    {
        o.style.backgroundImage = "url('ico/login_reg/button_mouseon.png')";
    }
    else
    {
	    o.setStyle('background-image', 'url(ico/login_reg/button_mouseon.png)');	
    }
}

function loginButtonMouseOut(o)
{
    if (browser.ie)
    {
        o.style.backgroundImage = "url('ico/login_reg/button_normal.png')";
    }
    else
    {
	    o.setStyle('background-image', 'url(ico/login_reg/button_normal.png)');	
    }
}

function loginButtonMouseDown(o)
{
    if (browser.ie)
    {
        o.style.backgroundImage = "url('ico/login_reg/button_click.png')";
    }
    else
    {
	    o.setStyle('background-image', 'url(ico/login_reg/button_click.png)');	
    }
}

function loginButtonMouseUp(o)
{
    if (browser.ie)
    {
        o.style.backgroundImage = "url('ico/login_reg/button_mouseon.png')";
    }
    else
    {
	    o.setStyle('background-image', 'url(ico/login_reg/button_mouseon.png)');	
    }
}

function inputblur(o)
{
	if (o.value.length > 5 && o.value.length < 21)
	{
		$('message').innerHTML = "<span class='messageclass' style='color:#090'>密码有效</span>";
        ready = true;
	}
	else
	{
		$('message').innerHTML = "<span class='messageclass' style='color:#F00'>密码长度应为6-20</span>";
        ready = false;
	}
}

function changePassword()
{
    inputblur($('password'));
    if (ready)
    {
    	var xmlhttp;
    	if (window.XMLHttpRequest)
      	{// code for IE7+, Firefox, Chrome, Opera, Safari
      		xmlhttp=new XMLHttpRequest();
      	}
    	else
      	{// code for IE6, IE5
      		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      	}
    	xmlhttp.onreadystatechange=function()
      	{
  		    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    	    {
                if (xmlhttp.responseText == 'success')
                {
                    myAlert('修改成功</br>3秒后自动跳转...');
                    setTimeout(function() {$('result').innerHTML = '修改成功</br>2秒后自动跳转...';},1000);
                    setTimeout(function() {$('result').innerHTML = '修改成功</br>1秒后自动跳转...';},2000);
                    setTimeout(function() {self.location = 'http://shiliu.tv';},3000);
                }
                else
                {
                    myAlert('修改出错');
                }
            }
      	}
    	xmlhttp.open("POST","forgetButChangePassword.php",true);
    	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
    	xmlhttp.send("password=" + $j('#password').val() + "&id=" + $('userid').innerHTML);
    }
}
function myAlert(message)
{
    $j('#changepassword').empty();
    $('changepassword').innerHTML = " <div id='logo'><img src='ico/logo4.png' /></div>";
    new Element('div', {'id':'result'}).inject($('changepassword'));
    $('result').innerHTML = message;
}
